package org.minproject.my_library_back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.minproject.my_library_back.controller.BookController;
import org.minproject.my_library_back.domain.Book;
import org.minproject.my_library_back.service.BookService;
import org.minproject.my_library_back.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【book】的数据库操作Service实现
* @createDate 2024-11-21 09:11:46
*/
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book>  implements BookService{
    @Autowired
    private BookMapper bookMapper;
    private  QueryWrapper<Book> queryWrapper = new QueryWrapper<Book>();

    @Override
    public int updateBook(Book book) {
        return bookMapper.updateById(book);
    }

    @Override
    public int deleteBook(Integer bookId) {
        return bookMapper.deleteById(bookId);
    }

    @Override
    public int addBook(Book book) {
        return bookMapper.insert(book);
    }

    @Override
    public List<Book> selectAllBooks() {
        return bookMapper.selectList(null);
    }

    @Override
    public List<Book> selectBookByName(String bookName) {
        return bookMapper.selectList(queryWrapper.like("book_name",bookName));
    }

    @Override
    public Book selectBookById(Integer bookId) {
        return bookMapper.selectOne(queryWrapper.eq("book_id",bookId));
    }
}




